{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "e98a7c3b",
   "metadata": {},
   "outputs": [],
   "source": [
    "# Python3_Jupyter_Nb_Excel数据提取_Horizontal_张海艳.ipynb\n",
    "# Create By GF 2023-11-17 11:54"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "7ecfcd1a",
   "metadata": {},
   "outputs": [],
   "source": [
    "import pandas as pd"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "3915ab64",
   "metadata": {},
   "outputs": [],
   "source": [
    "from Python3_DataProcFunc import *"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "cac9b86e",
   "metadata": {},
   "outputs": [],
   "source": [
    "df = pd.read_excel(\"./所有机型价格对比新张海艳11月14.xlsx\", sheet_name=\"2019-10月价格对比\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "b00c32dc",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>机型</th>\n",
       "      <th>官网价</th>\n",
       "      <th>官网价.1</th>\n",
       "      <th>零售价格</th>\n",
       "      <th>E商成本</th>\n",
       "      <th>预估毛利</th>\n",
       "      <th>历史最低价格出现时间（截止2023.6月）</th>\n",
       "      <th>历史最低月份</th>\n",
       "      <th>上半年最低价格出现时间</th>\n",
       "      <th>下半年出现最低价格时间</th>\n",
       "      <th>...</th>\n",
       "      <th>17云南</th>\n",
       "      <th>16云南</th>\n",
       "      <th>15云南</th>\n",
       "      <th>14云南</th>\n",
       "      <th>11云南</th>\n",
       "      <th>10云南</th>\n",
       "      <th>9云南</th>\n",
       "      <th>8云南</th>\n",
       "      <th>7云南</th>\n",
       "      <th>7其他</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>苹果(10代)ipad10.9-wifi-64G蓝</td>\n",
       "      <td>3599.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>2899.0</td>\n",
       "      <td>2877.55</td>\n",
       "      <td>21.45</td>\n",
       "      <td>2022.10.27-10.31</td>\n",
       "      <td>2022.10</td>\n",
       "      <td>10月发布</td>\n",
       "      <td>2022.10</td>\n",
       "      <td>...</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>苹果(10代)ipad10.9-wifi-64G粉</td>\n",
       "      <td>3599.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>2899.0</td>\n",
       "      <td>2877.55</td>\n",
       "      <td>21.45</td>\n",
       "      <td>2022.10.</td>\n",
       "      <td>2022.10</td>\n",
       "      <td>10月发布</td>\n",
       "      <td>2022.10</td>\n",
       "      <td>...</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>苹果(10代)ipad10.9-wifi-64G银</td>\n",
       "      <td>3599.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>2899.0</td>\n",
       "      <td>2877.55</td>\n",
       "      <td>21.45</td>\n",
       "      <td>2022.10.</td>\n",
       "      <td>2022.10</td>\n",
       "      <td>10月发布</td>\n",
       "      <td>2022.10</td>\n",
       "      <td>...</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>苹果(10代)ipad10.9-wifi-64G黄</td>\n",
       "      <td>3599.0</td>\n",
       "      <td>499.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>2022.10.</td>\n",
       "      <td>2022.10</td>\n",
       "      <td>10月发布</td>\n",
       "      <td>2022.10</td>\n",
       "      <td>...</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>苹果(10代)ipad10.9-wifi-256G蓝</td>\n",
       "      <td>4799.0</td>\n",
       "      <td>579.0</td>\n",
       "      <td>3899.0</td>\n",
       "      <td>3898.03</td>\n",
       "      <td>0.97</td>\n",
       "      <td>2022.10.</td>\n",
       "      <td>2022.10</td>\n",
       "      <td>10月发布</td>\n",
       "      <td>2022.10</td>\n",
       "      <td>...</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>919</th>\n",
       "      <td>苹果一体机24寸M3 8-10 8+512蓝MQRR3CH/A</td>\n",
       "      <td>13999.0</td>\n",
       "      <td>13999.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>2023.10.31发布</td>\n",
       "      <td>NaN</td>\n",
       "      <td>...</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>920</th>\n",
       "      <td>苹果一体机24寸M3 8-10 8+512银MQRK3CH/A</td>\n",
       "      <td>13999.0</td>\n",
       "      <td>13999.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>2023.10.31发布</td>\n",
       "      <td>NaN</td>\n",
       "      <td>...</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>921</th>\n",
       "      <td>苹果一体机24寸M3 8-10 8+512黄Z19G</td>\n",
       "      <td>13999.0</td>\n",
       "      <td>13999.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>2023.10.31发布</td>\n",
       "      <td>NaN</td>\n",
       "      <td>...</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>922</th>\n",
       "      <td>苹果一体机24寸M3 8-10 8+512橙Z19S</td>\n",
       "      <td>13999.0</td>\n",
       "      <td>13999.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>2023.10.31发布</td>\n",
       "      <td>NaN</td>\n",
       "      <td>...</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>923</th>\n",
       "      <td>苹果一体机24寸M3 8-10 8+512紫Z19Q</td>\n",
       "      <td>13999.0</td>\n",
       "      <td>13999.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>2023.10.31发布</td>\n",
       "      <td>NaN</td>\n",
       "      <td>...</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>924 rows × 3072 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "                                    机型      官网价    官网价.1    零售价格     E商成本  \\\n",
       "0            苹果(10代)ipad10.9-wifi-64G蓝   3599.0      NaN  2899.0  2877.55   \n",
       "1            苹果(10代)ipad10.9-wifi-64G粉   3599.0      NaN  2899.0  2877.55   \n",
       "2            苹果(10代)ipad10.9-wifi-64G银   3599.0      NaN  2899.0  2877.55   \n",
       "3            苹果(10代)ipad10.9-wifi-64G黄   3599.0    499.0     NaN      NaN   \n",
       "4           苹果(10代)ipad10.9-wifi-256G蓝   4799.0    579.0  3899.0  3898.03   \n",
       "..                                 ...      ...      ...     ...      ...   \n",
       "919  苹果一体机24寸M3 8-10 8+512蓝MQRR3CH/A    13999.0  13999.0     NaN      NaN   \n",
       "920  苹果一体机24寸M3 8-10 8+512银MQRK3CH/A    13999.0  13999.0     NaN      NaN   \n",
       "921       苹果一体机24寸M3 8-10 8+512黄Z19G    13999.0  13999.0     NaN      NaN   \n",
       "922       苹果一体机24寸M3 8-10 8+512橙Z19S    13999.0  13999.0     NaN      NaN   \n",
       "923       苹果一体机24寸M3 8-10 8+512紫Z19Q    13999.0  13999.0     NaN      NaN   \n",
       "\n",
       "      预估毛利 历史最低价格出现时间（截止2023.6月）   历史最低月份   上半年最低价格出现时间 下半年出现最低价格时间  ...  \\\n",
       "0    21.45      2022.10.27-10.31  2022.10         10月发布     2022.10  ...   \n",
       "1    21.45              2022.10.  2022.10         10月发布     2022.10  ...   \n",
       "2    21.45              2022.10.  2022.10         10月发布     2022.10  ...   \n",
       "3      NaN              2022.10.  2022.10         10月发布     2022.10  ...   \n",
       "4     0.97              2022.10.  2022.10         10月发布     2022.10  ...   \n",
       "..     ...                   ...      ...           ...         ...  ...   \n",
       "919    NaN                   NaN      NaN  2023.10.31发布         NaN  ...   \n",
       "920    NaN                   NaN      NaN  2023.10.31发布         NaN  ...   \n",
       "921    NaN                   NaN      NaN  2023.10.31发布         NaN  ...   \n",
       "922    NaN                   NaN      NaN  2023.10.31发布         NaN  ...   \n",
       "923    NaN                   NaN      NaN  2023.10.31发布         NaN  ...   \n",
       "\n",
       "     17云南  16云南  15云南  14云南 11云南 10云南 9云南 8云南 7云南 7其他  \n",
       "0     NaN   NaN   NaN   NaN  NaN  NaN NaN NaN NaN NaN  \n",
       "1     NaN   NaN   NaN   NaN  NaN  NaN NaN NaN NaN NaN  \n",
       "2     NaN   NaN   NaN   NaN  NaN  NaN NaN NaN NaN NaN  \n",
       "3     NaN   NaN   NaN   NaN  NaN  NaN NaN NaN NaN NaN  \n",
       "4     NaN   NaN   NaN   NaN  NaN  NaN NaN NaN NaN NaN  \n",
       "..    ...   ...   ...   ...  ...  ...  ..  ..  ..  ..  \n",
       "919   NaN   NaN   NaN   NaN  NaN  NaN NaN NaN NaN NaN  \n",
       "920   NaN   NaN   NaN   NaN  NaN  NaN NaN NaN NaN NaN  \n",
       "921   NaN   NaN   NaN   NaN  NaN  NaN NaN NaN NaN NaN  \n",
       "922   NaN   NaN   NaN   NaN  NaN  NaN NaN NaN NaN NaN  \n",
       "923   NaN   NaN   NaN   NaN  NaN  NaN NaN NaN NaN NaN  \n",
       "\n",
       "[924 rows x 3072 columns]"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 清洗(Wash)表头: \n",
    "# --------------------------------------------------\n",
    "Copy = df\n",
    "Copy.columns = [DataProcFunc_Pandas_Col_Name_Replace(ColName, \" \", str('')) for ColName in Copy.columns]\n",
    "Copy.columns = [DataProcFunc_Pandas_Col_Name_Replace(ColName, \"补\", str('')) for ColName in Copy.columns]\n",
    "Copy.columns = [DataProcFunc_Pandas_Col_Name_Replace(ColName, \"日\", str('')) for ColName in Copy.columns]\n",
    "Copy.columns = [DataProcFunc_Pandas_Col_Name_Replace(ColName, \"补充\", str('')) for ColName in Copy.columns]\n",
    "Copy.columns = [DataProcFunc_Pandas_Col_Name_Replace(ColName, \"含税\", str('')) for ColName in Copy.columns]\n",
    "Copy.columns = [DataProcFunc_Pandas_Col_Name_Replace(ColName, \"收盘\", str('')) for ColName in Copy.columns]\n",
    "Copy.columns = [DataProcFunc_Date_Form_Str_Standardization(ColName) for ColName in Copy.columns]\n",
    "# --------------------------------------------------\n",
    "# Method Explain: map()函数可以将一个函数映射到每个列名上.\n",
    "#df.columns = df.columns.map(lambda x: x.replace('_', ''))\n",
    "# --------------------------------------------------\n",
    "# Method Explain: 使用列表推导式快速地对列名称进行处理.\n",
    "#df.columns = [Col.replace(\"收盘\", str('')) for Col in df.columns]\n",
    "# --------------------------------------------------\n",
    "Copy"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "1ca58dcc",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>index</th>\n",
       "      <th>机型</th>\n",
       "      <th>官网价</th>\n",
       "      <th>官网价.1</th>\n",
       "      <th>零售价格</th>\n",
       "      <th>E商成本</th>\n",
       "      <th>预估毛利</th>\n",
       "      <th>历史最低价格出现时间（截止2023.6月）</th>\n",
       "      <th>历史最低月份</th>\n",
       "      <th>上半年最低价格出现时间</th>\n",
       "      <th>...</th>\n",
       "      <th>17云南</th>\n",
       "      <th>16云南</th>\n",
       "      <th>15云南</th>\n",
       "      <th>14云南</th>\n",
       "      <th>11云南</th>\n",
       "      <th>10云南</th>\n",
       "      <th>9云南</th>\n",
       "      <th>8云南</th>\n",
       "      <th>7云南</th>\n",
       "      <th>7其他</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>10</td>\n",
       "      <td>苹果(9代)ipad10.2-wifi-64G深空灰</td>\n",
       "      <td>2599.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>2099.0</td>\n",
       "      <td>2009.49</td>\n",
       "      <td>89.51</td>\n",
       "      <td>2022.8</td>\n",
       "      <td>2022.8</td>\n",
       "      <td>2022.6</td>\n",
       "      <td>...</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>1 rows × 3073 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "   index                          机型     官网价  官网价.1    零售价格     E商成本   预估毛利  \\\n",
       "0     10  苹果(9代)ipad10.2-wifi-64G深空灰  2599.0    NaN  2099.0  2009.49  89.51   \n",
       "\n",
       "  历史最低价格出现时间（截止2023.6月）  历史最低月份 上半年最低价格出现时间  ... 17云南  16云南  15云南  14云南  11云南  \\\n",
       "0                2022.8  2022.8      2022.6  ...  NaN   NaN   NaN   NaN   NaN   \n",
       "\n",
       "  10云南 9云南 8云南 7云南 7其他  \n",
       "0  NaN NaN NaN NaN NaN  \n",
       "\n",
       "[1 rows x 3073 columns]"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 筛选数据: \n",
    "# --------------------------------------------------\n",
    "Filter = Copy[(Copy[\"机型\"].str.contains(\"\\(9代\\)ipad\", regex=True)) &\n",
    "              (Copy[\"机型\"].str.contains(\"64\", regex=True)) &\n",
    "              (Copy[\"机型\"].str.contains(\"灰\", regex=True)) &\n",
    "              (Copy[\"机型\"].str.contains(\"^(?!.*max.*)\", regex=True))] # -> Regex中有(?=a)和(?!a)来表示是否需要某个字符。\n",
    "# --------------------------------------------------\n",
    "Filter = Filter.reset_index()\n",
    "# --------------------------------------------------\n",
    "Obj_Name = Filter[\"机型\"][0]\n",
    "# --------------------------------------------------\n",
    "Filter"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "e2b5d01d",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>日期</th>\n",
       "      <th>苹果(9代)ipad10.2-wifi-64G深空灰</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>机型</td>\n",
       "      <td>苹果(9代)ipad10.2-wifi-64G深空灰</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>2023.11.13</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>2023.11.12</td>\n",
       "      <td>1835-1845</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>2023.11.11</td>\n",
       "      <td>1830-1840</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>2023.11.10</td>\n",
       "      <td>1830-1840</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1687</th>\n",
       "      <td>2020.5.9</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1688</th>\n",
       "      <td>2020.4.5</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1689</th>\n",
       "      <td>2020.4.5</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1690</th>\n",
       "      <td>2020.3.20</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1691</th>\n",
       "      <td>2020.3.20</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>1692 rows × 2 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "              日期  苹果(9代)ipad10.2-wifi-64G深空灰\n",
       "0             机型  苹果(9代)ipad10.2-wifi-64G深空灰\n",
       "1     2023.11.13                         NaN\n",
       "2     2023.11.12                   1835-1845\n",
       "3     2023.11.11                   1830-1840\n",
       "4     2023.11.10                   1830-1840\n",
       "...          ...                         ...\n",
       "1687    2020.5.9                         NaN\n",
       "1688    2020.4.5                         NaN\n",
       "1689    2020.4.5                         NaN\n",
       "1690   2020.3.20                         NaN\n",
       "1691   2020.3.20                         NaN\n",
       "\n",
       "[1692 rows x 2 columns]"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 转置数据: \n",
    "# --------------------------------------------------\n",
    "Trs = Filter\n",
    "# --------------------------------------------------\n",
    "Filter_Date_Form_ColName = [Col for Col in Trs.columns if DataProcFunc_Judge_Str_Is_Date_Form(Col) == 1];\n",
    "# --------------------------------------------------\n",
    "# Code Explain: Filter Columns Name That Meets The Criteria.\n",
    "Trs = Trs[[\"机型\"] + Filter_Date_Form_ColName] # -> Equivalent to: Filter_Date_Form_ColName.insert(0, \"机型\")\n",
    "# --------------------------------------------------\n",
    "# Function Explain:\n",
    "# Transpose Data.\n",
    "Trs = Trs.transpose() # -> Equivalent to: TRS.T\n",
    "# --------------------------------------------------\n",
    "# Function Explain:\n",
    "# Convert All Old Indexes to Columns and Reset a New Sequential Index.\n",
    "# 将旧索引全部转化为列, 并重置一个新的顺序索引.\n",
    "# Option: drop=False # -> 把旧的索引全部删除, 并重置一个新的顺序索引.\n",
    "# Option: inplace=True # -> 在原DataFrame上进行更改.\n",
    "# Option: level=\"机型\" # -> 从多索引中释放特定的索引列, Equivalent to level=0.\n",
    "Trs = Trs.reset_index()\n",
    "# --------------------------------------------------\n",
    "Trs = Trs.rename(columns={\"index\":\"日期\", 0:Obj_Name})\n",
    "# --------------------------------------------------\n",
    "Trs"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "05e28439",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>日期</th>\n",
       "      <th>苹果(9代)ipad10.2-wifi-64G深空灰</th>\n",
       "      <th>名称</th>\n",
       "      <th>最高</th>\n",
       "      <th>最低</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>2021-09-23</td>\n",
       "      <td>[2420, 2440]</td>\n",
       "      <td>苹果(9代)ipad10.2-wifi-64G深空灰</td>\n",
       "      <td>2440.0</td>\n",
       "      <td>2420.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>2021-09-24</td>\n",
       "      <td>[2400, 2420]</td>\n",
       "      <td>苹果(9代)ipad10.2-wifi-64G深空灰</td>\n",
       "      <td>2420.0</td>\n",
       "      <td>2400.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>2021-09-25</td>\n",
       "      <td>[2400, 2420]</td>\n",
       "      <td>苹果(9代)ipad10.2-wifi-64G深空灰</td>\n",
       "      <td>2420.0</td>\n",
       "      <td>2400.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>2021-09-26</td>\n",
       "      <td>[2385, 2400]</td>\n",
       "      <td>苹果(9代)ipad10.2-wifi-64G深空灰</td>\n",
       "      <td>2400.0</td>\n",
       "      <td>2385.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>2021-09-27</td>\n",
       "      <td>[2390, 2420]</td>\n",
       "      <td>苹果(9代)ipad10.2-wifi-64G深空灰</td>\n",
       "      <td>2420.0</td>\n",
       "      <td>2390.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>779</th>\n",
       "      <td>2023-11-08</td>\n",
       "      <td>[1850, 1865]</td>\n",
       "      <td>苹果(9代)ipad10.2-wifi-64G深空灰</td>\n",
       "      <td>1865.0</td>\n",
       "      <td>1850.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>780</th>\n",
       "      <td>2023-11-09</td>\n",
       "      <td>[1855, 1860]</td>\n",
       "      <td>苹果(9代)ipad10.2-wifi-64G深空灰</td>\n",
       "      <td>1860.0</td>\n",
       "      <td>1855.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>781</th>\n",
       "      <td>2023-11-10</td>\n",
       "      <td>[1830, 1840]</td>\n",
       "      <td>苹果(9代)ipad10.2-wifi-64G深空灰</td>\n",
       "      <td>1840.0</td>\n",
       "      <td>1830.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>782</th>\n",
       "      <td>2023-11-11</td>\n",
       "      <td>[1830, 1840]</td>\n",
       "      <td>苹果(9代)ipad10.2-wifi-64G深空灰</td>\n",
       "      <td>1840.0</td>\n",
       "      <td>1830.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>783</th>\n",
       "      <td>2023-11-12</td>\n",
       "      <td>[1835, 1845]</td>\n",
       "      <td>苹果(9代)ipad10.2-wifi-64G深空灰</td>\n",
       "      <td>1845.0</td>\n",
       "      <td>1835.0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>784 rows × 5 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "            日期 苹果(9代)ipad10.2-wifi-64G深空灰                          名称      最高  \\\n",
       "0   2021-09-23               [2420, 2440]  苹果(9代)ipad10.2-wifi-64G深空灰  2440.0   \n",
       "1   2021-09-24               [2400, 2420]  苹果(9代)ipad10.2-wifi-64G深空灰  2420.0   \n",
       "2   2021-09-25               [2400, 2420]  苹果(9代)ipad10.2-wifi-64G深空灰  2420.0   \n",
       "3   2021-09-26               [2385, 2400]  苹果(9代)ipad10.2-wifi-64G深空灰  2400.0   \n",
       "4   2021-09-27               [2390, 2420]  苹果(9代)ipad10.2-wifi-64G深空灰  2420.0   \n",
       "..         ...                        ...                         ...     ...   \n",
       "779 2023-11-08               [1850, 1865]  苹果(9代)ipad10.2-wifi-64G深空灰  1865.0   \n",
       "780 2023-11-09               [1855, 1860]  苹果(9代)ipad10.2-wifi-64G深空灰  1860.0   \n",
       "781 2023-11-10               [1830, 1840]  苹果(9代)ipad10.2-wifi-64G深空灰  1840.0   \n",
       "782 2023-11-11               [1830, 1840]  苹果(9代)ipad10.2-wifi-64G深空灰  1840.0   \n",
       "783 2023-11-12               [1835, 1845]  苹果(9代)ipad10.2-wifi-64G深空灰  1845.0   \n",
       "\n",
       "         最低  \n",
       "0    2420.0  \n",
       "1    2400.0  \n",
       "2    2400.0  \n",
       "3    2385.0  \n",
       "4    2390.0  \n",
       "..      ...  \n",
       "779  1850.0  \n",
       "780  1855.0  \n",
       "781  1830.0  \n",
       "782  1830.0  \n",
       "783  1835.0  \n",
       "\n",
       "[784 rows x 5 columns]"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 调整数据: \n",
    "# --------------------------------------------------\n",
    "Adjust = Trs\n",
    "# --------------------------------------------------\n",
    "# Function Explain:\n",
    "# Delete Rows or Columns.\n",
    "# Use \"axis=0\" to Delete Rows, and Use \"axis=1\" to Delete Columns.\n",
    "Adjust = Adjust.drop(labels=0, axis=0) # Code Explain: Delete Rows With Row Index 0 Equivalent to labels=\"机型\".\n",
    "# --------------------------------------------------\n",
    "Adjust[\"日期\"] = Adjust[\"日期\"].astype(\"datetime64[ns]\")\n",
    "Adjust = Adjust.sort_values(\"日期\", ascending=True)\n",
    "# --------------------------------------------------\n",
    "Adjust = Adjust.dropna(axis=0, how=\"any\")\n",
    "# --------------------------------------------------\n",
    "Adjust[Obj_Name] = Adjust[Obj_Name].apply(lambda x: DataProcFunc_Pandas_Digit_Form_StrVal_Tail_Wash(x))\n",
    "Adjust[Obj_Name] = Adjust[Obj_Name].apply(lambda x: DataProcFunc_Pandas_StrVal_Replace(x, \"*\", str('')))\n",
    "Adjust[Obj_Name] = Adjust[Obj_Name].apply(lambda x: DataProcFunc_Pandas_StrVal_Replace(x, \"含税\", str('')))\n",
    "Adjust[Obj_Name] = Adjust[Obj_Name].apply(lambda x: DataProcFunc_Pandas_StrVal_Split_To_List_Skip_Other(x, '-'))\n",
    "Adjust[Obj_Name] = Adjust[Obj_Name].apply(lambda x: DataProcFunc_Pandas_StrVal_Split_To_List_Skip_Other(x, '/'))\n",
    "# --------------------------------------------------\n",
    "Adjust = DataProcFunc_Pandas_Delete_Rows_By_Contains_StrVal_All(Adjust, '0', 1).reset_index(drop=True)\n",
    "Adjust = DataProcFunc_Pandas_Delete_Rows_By_Contains_StrVal_All(Adjust, '0.0', 1).reset_index(drop=True)\n",
    "# --------------------------------------------------\n",
    "Adjust[\"名称\"] = Obj_Name\n",
    "Adjust[\"最高\"] = Adjust[Obj_Name].apply(lambda x: DataProcFunc_Pandas_DigStr_Or_StrList_Max(x))\n",
    "Adjust[\"最低\"] = Adjust[Obj_Name].apply(lambda x: DataProcFunc_Pandas_DigStr_Or_StrList_Min(x))\n",
    "# --------------------------------------------------\n",
    "Adjust"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "cb174c1b",
   "metadata": {},
   "outputs": [],
   "source": [
    "Adjust[[\"日期\", \"名称\", \"最高\", \"最低\"]].to_csv(\"./Test.csv\", index=False)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "278ba8f5",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.0"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
